﻿namespace Resharper.Abstractions.CodeDom.Expressions.AsOperatorExpressions
{
  using System;
  using JetBrains.Annotations;
  using JetBrains.ReSharper.Psi.CSharp.Tree;
  using Resharper.Abstractions.Actions;
  using Resharper.Abstractions.CodeDom.Expressions.InvocationExpressions;

  /// <summary>Defines the <see cref="InvocationExpressionExtensions"/> class.</summary>
  public static class AsOperatorExpressionExtensions
  {
    #region Public Methods

    /// <summary>Gets the selected literal expression.</summary>
    /// <param name="context">The context.</param>
    /// <returns>Returns the selected literal expression.</returns>
    [CanBeNull]
    public static AsOperatorExpression GetSelectedAsOperatorExpression([NotNull] this ProviderContext context)
    {
      if (context == null)
      {
        throw new ArgumentNullException("context");
      }

      var invocationExpression = context.InternalGetSelectedElement<IAsExpression>();

      return invocationExpression != null ? new AsOperatorExpression(invocationExpression) : null;
    }

    #endregion
  }
}